// license-header java merge-point
/**
 * This is only generated once! It will never be overwritten.
 * You can (and have to!) safely modify it by hand.
 * TEMPLATE:    SpringServiceImpl.vsl in andromda-spring cartridge
 * MODEL CLASS: AndroMDAModel::JR Appointment Service::com.systemsjr.jrappointment::user::service::SecurityService
 * STEREOTYPE:  Service
 */
package com.systemsjr.jrappointment.user.service;

import java.util.Collection;

import com.systemsjr.jrappointment.user.vo.UserDetailsVO;
import com.systemsjr.jrappointment.user.vo.UserSearchCriteria;

/**
 * @see com.systemsjr.jrappointment.user.service.SecurityService
 */
public class SecurityServiceImpl
    extends SecurityServiceBase
{

    /**
     * @see com.systemsjr.jrappointment.user.service.SecurityService#getUserDetails(String)
     */
    protected  UserDetailsVO handleGetUserDetails(String username)
        throws Exception
    {
    	UserSearchCriteria criteria = new UserSearchCriteria();
    	criteria.setUsername(username);
    	
    	Collection u = getUserDao().findByCriteria(criteria);  
    	
    	UserDetailsVO[] users = getUserDao().toUserDetailsVOArray(u);
    	
    	if(users.length > 1 || users.length == 0){
    		throw new UnsupportedOperationException("Wrong credetials");
    	}
    	
    	return users[0];
        
    }

}